package com.song.controller;


import com.song.entity.Lend;
import com.song.result.Result;
import com.song.service.LendService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 标的准备表 前端控制器
 * </p>
 *
 * @author Song
 * @since 2025-01-03
 */
@RestController
@RequestMapping("/api/core/lend")
public class LendController {

    @Autowired
    private LendService lendService;


    /**
     * 显示所有标的
     * @return
     */
    //http://localhost/api/core/lend/list
    @ApiOperation("显示所有标的的方法")
    @GetMapping("/list")
    public Result list(){

        List<Lend> lendList = lendService.selectList();
        return Result.ok().data("lendList",lendList);
    }


    // /api/core/lend/show/lendId
    @ApiOperation("获取标的的信息")
    @GetMapping("/show/{lendId}")
    public  Result show(@ApiParam(value = "标的id",required = true) @PathVariable Long lendId){

        Map<String, Object> lendDetail = lendService.getLendDetailById(lendId);

        return Result.ok().data("lendDetail",lendDetail);

    }

  //  /api/core/lend/getInterestCount/${this.invest.investAmount}/${this.lend.lendYearRate}/${this.lend.period}/${this.lend.returnMethod}
  @ApiOperation("计算收益")
  @GetMapping("/getInterestCount/{investAmount}/{lendYearRate}/{period}/{returnMethod}")
  public Result getInterestCount(
          @ApiParam(value = "投资金额",required = true)
          @PathVariable("investAmount")BigDecimal investAmount,

          @ApiParam(value = "年化利率",required = true)
          @PathVariable("lendYearRate")BigDecimal lendYearRate,

          @ApiParam(value = "期数",required = true)
          @PathVariable("period")Integer period,

          @ApiParam(value = "还款方式",required = true)
          @PathVariable("returnMethod")Integer returnMethod
  ){
      BigDecimal money=  lendService.getInterestCount(investAmount,lendYearRate,period,returnMethod);

      return Result.ok().data("interestCount",money);

  }

}

